#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# 在提交前运行简化版的代码检查
echo "Running pre-commit checks..."

# 获取暂存的文件
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts)$')

# 如果没有 JS/TS 文件变更，则跳过
if [ -z "$FILES" ]; then
  echo "No JS/TS files to check. Skipping lint-staged."
  exit 0
fi

# 运行 lint-staged，仅执行格式化和简单 lint
if ! npx lint-staged --no-stash; then
  echo "❌ Pre-commit checks failed. You can:"
  echo "  1. Fix the issues and try committing again"
  echo "  2. Use 'git commit --no-verify' to bypass checks (not recommended)"
  exit 1
fi

echo "✅ Pre-commit checks passed!" 